package com.bootdo.put.controller;

import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.bootdo.put.service.PutStorageService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.put.domain.PutStorageDetailDO;
import com.bootdo.put.service.PutStorageDetailService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 入库单详情controller类
 * 
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2018-04-24 11:50:15
 */
 
@Controller
@RequestMapping("/put/putStorageDetail")
public class PutStorageDetailController {
	@Autowired
	private PutStorageDetailService putStorageDetailService;
	@Autowired
	private PutStorageService putStorageService;
	
	@GetMapping()
	//@RequiresPermissions("put:putStorageDetail:putStorageDetail")
	String PutStorageDetail(@RequestParam(required = false) Long putId,Model model){
		System.out.println("putId:"+putId);
		model.addAttribute("putId",putId);
		System.out.println("putStorageDO:"+JSON.toJSON(putStorageService.get(putId)));
		model.addAttribute("putStorageDO",putStorageService.get(putId));
	    return "put/putStorageDetail/putStorageDetail";
	}
	@ResponseBody
	@GetMapping("/list")
	//@RequiresPermissions("put:putStorageDetail:putStorageDetail")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<PutStorageDetailDO> putStorageDetailList = putStorageDetailService.list(query);
		int total = putStorageDetailService.count(query);
		PageUtils pageUtils = new PageUtils(putStorageDetailList, total);
		return pageUtils;
	}
	
//	@GetMapping("/add")
//	String add(){
//	    return "put/putStorageDetail/add";
//	}

	@GetMapping("/edit/updates/{putDetailId}")
//	@RequiresPermissions("put:putStorageDetail:updates:edit")
	String edit(@PathVariable("putDetailId") Long putDetailId,Model model){
		PutStorageDetailDO putStorageDetail = putStorageDetailService.get(putDetailId);
		model.addAttribute("putStorageDetail", putStorageDetail);
	    return "put/putStorageDetail/updates/edit";
	}
	

	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/updates/updates")
	public R update( PutStorageDetailDO putStorageDetail){
		putStorageDetailService.update(putStorageDetail);
		return R.ok();
	}
	
//	/**
//	 * 删除
//	 */
//	@PostMapping( "/remove")
//	@ResponseBody
//	public R remove( Long putDetailId){
//		if(putStorageDetailService.remove(putDetailId)>0){
//		return R.ok();
//		}
//		return R.error();
//	}
//	
//	/**
//	 * 删除
//	 */
//	@PostMapping( "/batchRemove")
//	@ResponseBody
//	public R remove(@RequestParam("ids[]") Long[] putDetailIds){
//		putStorageDetailService.batchRemove(putDetailIds);
//		return R.ok();
//	}
	
}
